package com.qt.thread.homework.work2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * @Author zsf
 * @Date 2023/10/4 1:04
 * @Version 1.0
 */
public class CjxCallAble implements Callable<Integer> {

    private List<Integer> list;

    public CjxCallAble(List<Integer> list) {
        this.list = list;
    }


    @Override
    public Integer call() throws Exception {
        ArrayList<Integer> result = new ArrayList<>();
        while (true) {

            synchronized (CjxCallAble.class) {
                if (list.size() > 0) {
                    //int index = new Random().nextInt(list.size());
                    //System.out.println(Thread.currentThread().getName()+"又出现了" + list.get(index) +"大奖");
                    Collections.shuffle(list);
                    result.add(list.get(0));
                    list.remove(0);
                } else {
                    System.out.println(Thread.currentThread().getName() + "结果" + result.toString());
                    break;
                }

            }


        }
        if(result.size()==0){
           return 0;
        }
        return Collections.max(result);
    }
}
